﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace QD.Snapshot.Core.DAL
{
    public class WebSite : DAL.DAO
    {
        public static Dictionary<int, Model.WebSite> GetList(string ids, int pageSize = 1000)
        {
            Dictionary<int, Model.WebSite> list = null;
            string sql = string.Format("select top {0} userid,ShortName,SiteName,Cellphone,Phone from vifo_union_website where userid in ({1})", pageSize, ids);
            try
            {
                using (SqlConnection con = new SqlConnection(conString))
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand(sql, con);
                    cmd.CommandType = CommandType.Text;
                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                            list = new Dictionary<int, Model.WebSite>();
                        while (dr.Read())
                        {
                            Model.WebSite model = new Model.WebSite()
                            {
                                UserID = Convert.ToInt32(dr["UserID"]),
                                ShortName = Convert.ToString(dr["ShortName"]),
                                SiteName = Convert.ToString(dr["SiteName"]),
                                Cellphone = Convert.ToString(dr["Cellphone"]),
                                Phone = Convert.ToString(dr["Phone"])
                            };
                            list.Add(model.UserID, model);
                        }
                    }
                    con.Close();
                }
            }
            catch (Exception e) { }
            return list;
        }
    }
}